// pages/CheGuan/CheGuan.js
var util = require('../../utils/util.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navindex: 0,
    According: false,
    freightnav: [
      { txt: '已通过' },
      { txt: '审核中' },
      { txt: '未通过' },
      { txt: '未认证' },
    ],
    CheGuan:[
      // {
      //   time: '20178-09-06  14:59:12', state:'已通过',
      // },
    ],
    currentPage: 1,
    totalPage: 1,
    status:1
  },
  initPassCarList:function(){
    var that = this;
    var param = {
      status : that.data.status,
      currentPage: that.data.currentPage,
    };
 
    wx.showLoading({})
    util.commonRequest('carList', 'post', param, function (res) {
      wx.hideLoading();
      if (res.data.data.data.length == 0) {
        that.setData({
          According: true,
        })
      } else {
        that.setData({
          According: false,
        })
      }
      if (res.data.code == 200) {
        var tempArr = res.data.data.data;
        var oriArr = that.data.CheGuan;
        var finalyArr = oriArr.concat(tempArr);
     
        that.setData({
          CheGuan: finalyArr,
          totalPage: res.data.data.last_page
        })
      } else {
        wx.showToast({
          icon: 'loading',
          title: res.data.msg,
        })
      }
    });
  },
  //管理详情
  CheGuandeil(e) {
    var id = e.currentTarget.dataset.id;
    app.navTo('../CheGuandeil/CheGuandeil?id='+id)
  },
  //添加车辆
  start_addcar(){
    app.navTo('../addcar/addcar')
  },
  click: function (e) {
    var id = e.currentTarget.dataset.id;
    console.log(id) //0 1 2 3
    var tempStatus = 1;
    if(id == 0){
      tempStatus = 1;
    }
    if (id == 1) {
      tempStatus = 0;
    }
    if (id == 2) {
      tempStatus = 2;
    }
    if (id == 3) {
      tempStatus = 3;
    }
    this.setData({
      navindex: id,
      status:tempStatus,
      CheGuan:[],
      currentPage:1
    })
    this.initPassCarList();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
    this.setData({
      CheGuan: [],
      currentPage: 1
    })
    // var status = options.status;
    // var index = options.index;
    // if(status && index){
    //   this.setData({
    //     navindex:index,
    //     status: status
    //   })
    //   this.initPassCarList();
    // }
    let that = this;

    // that.initPassCarList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
    this.setData({
      CheGuan: [],
      currentPage: 1
    })
    let that = this;
    
    that.initPassCarList();
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var currentpage = this.data.currentPage;
    var totalpage = this.data.totalPage;
    if (currentpage < totalpage) {
      this.setData({
        currentPage: currentpage + 1
      })
      this.initPassCarList();
    } else {
      console.log("已经是全部数据")
      // wx.showToast({
      //   'icon':'loading',
      //   title: '已经是全部数据了',
      // })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})